package com.wwwarehouse.taskcenter.adapter.job_point;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;

import com.wwwarehouse.common.adapter.media.CommonAdapter;
import com.wwwarehouse.common.adapter.media.ViewHolder;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.job_point.CategoryInfoResponseBean;
import com.wwwarehouse.taskcenter.eventbus_event.JobPointStateEvent;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by Jackie on 2017/10/30.
 * 子作业点组合维度  选择添加方式  按类目添加  详情列表  适配器
 */

public class CategoryAdapter extends CommonAdapter<CategoryInfoResponseBean> {
    private int mItemHeight;

    public CategoryAdapter(Context context, int layoutId, List<CategoryInfoResponseBean> categoryDetailsList, int itemHeight) {
        super(context, layoutId, categoryDetailsList);

        this.mItemHeight = itemHeight;
    }

    @Override
    public void convert(ViewHolder holder, final CategoryInfoResponseBean categoryDetailsBean) {
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.height = mItemHeight;
        holder.getConvertView().setLayoutParams(params);

        final ImageView selectImg = holder.getView(R.id.iv_select);

        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                categoryDetailsBean.setSelect(!categoryDetailsBean.isSelect());

                notifyDataSetChanged();

                EventBus.getDefault().post(new JobPointStateEvent());
            }
        });

        holder.setText(R.id.tv_name, categoryDetailsBean.getCategoryName());

        if (categoryDetailsBean.isSelect()) {
            selectImg.setVisibility(View.VISIBLE);
        } else {
            selectImg.setVisibility(View.GONE);
        }
    }
}
